package com.example.lenovo.myapplication;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.sql.Time;

public class MainActivity extends AppCompatActivity {
private Button btn_sent;
private MyBroadcastReceiver receiver;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

         receiver = new MyBroadcastReceiver();
         IntentFilter filter =new IntentFilter();
         filter.addAction("Weather_Report");
         filter.addAction("Trafic_Report");
         registerReceiver(receiver,filter);

        btn_sent =findViewById(R.id.btn_sent);
        btn_sent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setAction("Weater_Report");
                intent.putExtra("weather","sun");
                intent.putExtra("temprature",25);
                sendBroadcast(intent);
            }
        });
        btn_sent=findViewById(R.id.btn_trafic);
        btn_sent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setAction("btn_trafic");
                intent.putExtra("Trafic","堵车");
                intent.putExtra("Time",40);
                sendBroadcast(intent);
            }
        });
    }
}
